Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PTBKey not extend ReferenceBinding #3452

Merged
merged 1 commit into from
Jan 20, 2025

Conversation

jukzi
Copy link
Contributor

@jukzi jukzi commented Dec 13, 2024

  • Introduces interface TypeBindingWrapper.
  • Removes little code from PTBKey that is irrelevant for the wrapper

relates to #3412

jukzi pushed a commit to jukzi/eclipse.jdt.core that referenced this pull request Dec 13, 2024
Its just an IdentityWrapper - do not rely on ReferenceBinding
implementation.

relates to
eclipse-jdt#3452
@jukzi
Copy link
Contributor Author

jukzi commented Dec 17, 2024

@srikanth-sankaran may i ask for review? I would like to improve ReferenceBinding in small steps.

@srikanth-sankaran
Copy link
Contributor

@srikanth-sankaran may i ask for review? I would like to improve ReferenceBinding in small steps.

I'll try - but can't promise, I am trying to wrap up some projects I am working on before this week since post that I am away till 2nd Jan.

jukzi pushed a commit that referenced this pull request Dec 17, 2024
Its just an IdentityWrapper - do not rely on ReferenceBinding
implementation.

relates to
#3452
@jukzi
Copy link
Contributor Author

jukzi commented Jan 7, 2025

@srikanth-sankaran ping, please review.

@srikanth-sankaran
Copy link
Contributor

Sure, I will look into these this week. Happy new year!

@srikanth-sankaran
Copy link
Contributor

Sure, I will look into these this week. Happy new year!

Sorry, it looks like my full return to work will be delayed until a few days more. I will be at work 3 out of 5 days next week and I am hopeful the review can be completed well ahead of M2.

Copy link
Contributor

@srikanth-sankaran srikanth-sankaran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments, need some clarifications on what exactly we are trying to accomplish here.

I am yet to come to grips with what the new additional interface buys us.

Also the title of the PR PTBKey is not a ReferenceBinding - need clarification. What exactly do you mean by that.

I don't see anything seriously wrong/faulty - but simply don't get yet where we are going with this and why

@@ -53,18 +53,18 @@ public TypeBinding clone(TypeBinding outerType) {
return copy;
}

void addWrapper(TypeBinding wrapper, LookupEnvironment environment) {
void addWrapper(TypeBindingWrapper wrapper, LookupEnvironment environment) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only usage of the proposed interface. Here the instance is called "wrapper" and the method name add"Wrapper" also suggest to have "Wapper" in the interface name. Thats why i chose "TypeBindingWrapper". but i would be fine with any other Name.

@jukzi jukzi changed the title PTBKey is not a ReferenceBinding PTBKey does not need to implement ReferenceBinding Jan 17, 2025
@jukzi jukzi force-pushed the TypeBindingWrapper branch from 54187ac to 068f092 Compare January 17, 2025 10:00
@srikanth-sankaran
Copy link
Contributor

Not sure if you are planning to explain the PR title change - the new one still doesn't clear the mystery for me :)

Do you have a scenario where the PTBKey is actually not a reference binding ??

Without the additional name TypeBindingWrapper being used, things were working so far - so what does extracting the swapUnresolved behavior into its own type buy us ?

@jukzi
Copy link
Contributor Author

jukzi commented Jan 17, 2025

Without the additional name TypeBindingWrapper being used, things were working so far - so what does extracting the swapUnresolved behavior into its own type buy us ?

I am trying to clean up the ReferenceBinding equals/hashCode contract as it hard to understand and errorprone to accidentialy use when using a ReferenceBinding as key (for example #3561 ). As this PTBKey does not need to implement ReferenceBinding one could just ignore the PTBKey in such scenarios. At the end it will be fine if the PTBKey will have a custom equals/hashcode, but any actual ReferenceBinding probably won't need to override equals/hashcode => no more worries in the future.

@jukzi jukzi force-pushed the TypeBindingWrapper branch from 068f092 to cf810f5 Compare January 17, 2025 10:13
@jukzi jukzi changed the title PTBKey does not need to implement ReferenceBinding Make PTBKey not extend ReferenceBinding Jan 17, 2025
@srikanth-sankaran
Copy link
Contributor

Without the additional name TypeBindingWrapper being used, things were working so far - so what does extracting the swapUnresolved behavior into its own type buy us ?

I am trying to clean up the ReferenceBinding equals/hashCode contract as it hard to understand and errorprone to accidentialy use when using a ReferenceBinding as key (for example #3561 ). As this PTBKey does not need to implement ReferenceBinding one could just ignore the PTBKey in such scenarios. At the end it will be fine if the PTBKey will have a custom equals/hashcode, but any actual ReferenceBinding probably won't need to override equals/hashcode => no more worries in the future.

PTBKey is not "implementing" ReferenceBinding but ISA ReferenceBinding - do you know of cases where it is NOT a ReferenceBinding ? If not this whole PR will become moot and will only serve to obfuscate by introducing additional names...

@jukzi
Copy link
Contributor Author

jukzi commented Jan 17, 2025

PTBKey is not "implementing" ReferenceBinding but ISA ReferenceBinding - do you know of cases where it is NOT a ReferenceBinding ? If not this whole PR will become moot and will only serve to obfuscate by introducing additional names...

It was a ReferenceBinding but did not need to be ReferenceBinding. It is only a wrapper used as key for ParameterizedTypeBinding. It is not used as ReferenceBinding itself anywhere. Especially PTBKey.hash(TypeBinding) will never call PTBKey.hashCode() which was not clear from the type hierarchy.

@srikanth-sankaran
Copy link
Contributor

PTBKey is not "implementing" ReferenceBinding but ISA ReferenceBinding - do you know of cases where it is NOT a ReferenceBinding ? If not this whole PR will become moot and will only serve to obfuscate by introducing additional names...

It was a ReferenceBinding but did not need to be ReferenceBinding. It is only a wrapper used as key for ParameterizedTypeBinding. It is not used as ReferenceBinding itself anywhere. Especially PTBKey.hash(TypeBinding) will never call PTBKey.hashCode() which was not clear from the type hierarchy.

OK, I finally have an understanding of what you are trying to do. With that in mind, taking a fresh relook ...

@srikanth-sankaran
Copy link
Contributor

srikanth-sankaran commented Jan 20, 2025

I have reviewed the fix and I don't have major objections to it.

Yes, the PTBKey behavior does not call for it to be a ReferenceBinding per se and to factor out the relevant behavior into an interface is OK.

(1) I am still not very happy with the name - Resolvable is way better than TypeBindingWrapper which was plain WRONG. In the original patch, TypeBinding was implementing TypeBindingWrapper - That is wrong. TypeBinding is actually a Wrappable and not a Wrapper (but see below)

But Resolvable is not precise enough. I wonder if a name like HotSwappable is more to the point. Sorry for overriding my own earlier suggestion and causing rework.

(2) A TypeBinding itself is not HotSwappable - ONLY those abstractions in the hierarchy that implement the method org.eclipse.jdt.internal.compiler.lookup.TypeBinding.swapUnresolved(UnresolvedReferenceBinding, ReferenceBinding, LookupEnvironment) are. That presently TypeBinding has a dummy/nop/placeholder implementation does not count.

I think this PR may look a lot better

- if `Resolvable` is renamed to be `HotSwappable` and
- if  `HotSwappable` is implemented ONLY by `ArrayBinding`, `ParameterizedTypeBinding`, `WildCardBinding`, `PTBKey` and `UnresolvedReferenceBinding` 
- if `TypeBinding` itself DOES NOT implement it

What do you think ? If you agree, you may proceed to make the changes and integrate once tests are green. Thanks

PTBKey needs a custom hashCode/equals contract, while ReferenceBinding
should not need any.

* PTBKey not extends ReferenceBinding anymore.
* Introduces interface HotSwappable.
* Removes little code from PTBKey that is irrelevant for the wrapper

relates to eclipse-jdt#3412
@jukzi jukzi force-pushed the TypeBindingWrapper branch from cf810f5 to c633101 Compare January 20, 2025 08:37
@jukzi
Copy link
Contributor Author

jukzi commented Jan 20, 2025

What do you think ? If you agree, you may proceed to make the changes and integrate once tests are green. Thanks

sounds good, changes applied

Copy link
Contributor

@srikanth-sankaran srikanth-sankaran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good. Please proceed to integrate assuming no surprises in testing.

@jukzi
Copy link
Contributor Author

jukzi commented Jan 20, 2025

the failing test is known to randomly fail: #2716 (comment)

@jukzi jukzi merged commit 121e230 into eclipse-jdt:master Jan 20, 2025
7 of 10 checks passed
@jukzi jukzi deleted the TypeBindingWrapper branch January 20, 2025 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants